﻿@model Himall.Web.Models.AgreementModel

<script src="~/Scripts/ueditor/ueditor.config.js"></script>
<script src="~/Scripts/ueditor/ueditor.all.min.js"></script>
<div class="container">
    <!--<ul class="nav nav-tabs-custom clearfix">
        <strong>协议管理</strong>
    </ul>-->
    <ul class="nav nav-tabs-custom clearfix">
        <li value="0" type="statusTab"><a>会员注册协议</a></li>
        <li value="1" type="statusTab"><a>卖家入驻协议</a></li>
        <em class="primary-btn">
            <span class="glyphicon glyphicon-question-sign"></span>
            <div class="primary">
                <h3>温馨提示：</h3>
                <span>*</span><p>协议管理</p>
            </div>
        </em>
    </ul>
    @using (Html.BeginForm("UpdateAgreement", "Agreement", FormMethod.Post))
    {
        <div class="form-horizontal">
            <div class="form-group">
                <input type="hidden" value="" id="hidRole" />
                <label for="" class="col-sm-2 control-label">协议内容：</label>
                <div class="col-sm-9">
                    <textarea id="des" maxlength="10000" name="AdminAgreement">@Model.AgreementContent</textarea>
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-offset-2 col-sm-10">
                    <input type="button" id="Save" class="btn btn-primary" value="保 存">
                </div>
            </div>
        </div>
    }
</div>

<script>
    var editor;
    $(function () {
        (function initRichTextEditor() {
            editor = UE.getEditor('des');
            editor.addListener('contentChange', function () {
                $('#contentError').hide();
            });

        })();
        //默认选中用户注册协议
        $('.nav li').each(function () {
            if ($(this).val() == '0') {
                $(this).addClass('active').siblings().removeClass('active');
                $("#hidRole").val($(this).attr('value'));
            }
        });
        //更新选中状态
        $('.nav li').click(function (e) {
            $(this).addClass('active').siblings().removeClass('active');
            $("#hidRole").val($(this).attr('value'));
            var loading = showLoading();
            $.ajax({
                type: 'post',
                url: "./GetManagement",
                cache: false,
                async: true,
                data: { agreementType: $("#hidRole").val() },
                dataType: "json",
                success: function (data) {
                    editor.setContent(data.AgreementContent);
                loading.close();
                }
            });

        });

        $("#Save").click(function () {
            var agreementType = $("#hidRole").val();
            var agreementContent = editor.getContent();
            var strLength = editor.getContentTxt().length
            //验证字符长度
            if (strLength > 10000) {
                $.dialog.tips('输入字符过长！');
                return;
            }
            var loading = showLoading();
            $.post("./UpdateAgreement", { agreementType: agreementType, agreementContent: agreementContent },
                function (result) {
                    if (result.success) {
                        $.dialog.tips('保存成功');
                    }
                    else
                        $.dialog.tips('保存失败！' + result.msg);
                    loading.close();
                });
        });
    });
</script>
